{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1200, 800, 3)\n"
     ]
    }
   ],
   "source": [
    "# 图片剪切\n",
    "# x: 100 -> 200\n",
    "# y: 100 -> 300\n",
    "import cv2\n",
    "img = cv2.imread('../../imags/test.jpeg',1)\n",
    "imgInfo = img.shape\n",
    "print(imgInfo)\n",
    "dst = img[100:200,100:300]\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "##图片位移\n",
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1)\n",
    "cv2.imshow('src',img)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "matShift = np.float32([[1,0,100],[0,1,200]]) # 2x 3\n",
    "dst = cv2.warpAffine(img,matShift,(width,height))   \n",
    "# cv2.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) → dst\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 图片位移原理\n",
    "# [[1,0,100],[0,1,200]]  可以分成2*2 2*1\n",
    "# [[1,0],[0,1]] 2*2 A \n",
    "# [[100],[200]] 2*1 B\n",
    "# xy C  [[x],[y]] 2*1\n",
    "# 计算  A*C + B -> [[1*x+0*y],[0*x+1*y]]+[[100],[200]] = [[x+100],[y+200]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1)\n",
    "cv2.imshow('src',img)\n",
    "imgInfo = img.shape\n",
    "dstImage = np.zeros(img.shape,np.uint8) ##空白模板\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "for i in range(200,height):\n",
    "    for j in range(100,width):\n",
    "        dstImage[i,j] = img[i-200,j-100]\n",
    "cv2.imshow('img',dstImage)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1200, 800, 3)\n"
     ]
    }
   ],
   "source": [
    "## 图片的上下镜像效果\n",
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1)\n",
    "cv2.imshow('src',img)\n",
    "imgInfo = img.shape\n",
    "print(imgInfo)\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "deep = imgInfo[2]\n",
    "newImgInfo=(height,width*2,deep)\n",
    "dst = np.zeros(newImgInfo,np.uint8)\n",
    "for i in range(0,height):\n",
    "    for j in range(0,width):\n",
    "        dst[i,j] = img[i,j]\n",
    "        dst[i,width+j] = img[i,800-1-j]\n",
    "    dst[i,width]=(0,0,255)\n",
    "cv2.imshow('img',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(0,10):\n",
    "    print(i)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
